﻿

using HrEFCore;
using HrService;
using Microsoft.AspNetCore.Mvc;

namespace HrUI.Controllers
{
	public class CFFKController : Controller
	{
		private readonly MyDbContext myDbContext;
		private readonly CFFKService cFFKService;
		public CFFKController(MyDbContext myDbContext, CFFKService cFFKService)
		{
			this.myDbContext = myDbContext;
			this.cFFKService = cFFKService;
		}

		//public IActionResult Index()
		//{
		//	return View();
		//}
		//查看cffk表
		public async Task<IActionResult> Index()
		{
			List<CFFK> list = await cFFKService.CFFKSelectAsync();
			ViewData.Model = list;
			return View();
		}
		//显示添加页面
		[HttpGet]
		public ActionResult Insert()
		{
			return View();
		}
		//添加数据
		[HttpPost]
		public async Task<ActionResult> CFFKAdd(CFFK cFFK)
		{
			int row = await cFFKService.CFFKInsertAsync(cFFK);
			if (row > 0)
			{
				Content("<script>alert('添加成功')</script>");
				return RedirectToAction("Index");
			}
			else
			{
				Content("<script>alert('添加失败')</script>");
				return View();
			}
		}
		//删除数据
		public async Task<ActionResult> CFFKDel(short id)
		{
			int row = await cFFKService.CFFKDelAsync(id);
			if (row > 0)
			{
				return RedirectToAction("Index");
			}
			else
			{
				return RedirectToAction("Index");
			}
		}
		public async Task<ActionResult> Update(short id)
		{
			CFFK cffk = await cFFKService.CFFKByIdAsync(id);
			ViewData.Model = cffk;
			return View();
		}
		public async Task<ActionResult> CFFKUpdate(CFFK cffk)
		{
			//if (ModelState.IsValid)
			//{
				int row = await cFFKService.CFFKUpdateAsync(cffk);
				if (row > 0)
				{
					Content("<script>alert('修改成功')</script>");
					return RedirectToAction("Index");
				}
				else
				{
					Content("<script>alert('修改失败')</script>");
					return View();
				}
			//}
			//else
			//{
			//	List<CFFK> list = await cFFKService.CFFKSelectAsync();
			//	ViewData.Model = list;
			//	return RedirectToAction("Update");
			//}
		}
	}
}
